package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.mapper.DiseaseMapper;
import com.itheima.pojo.Disease;
import com.itheima.service.DiseaseService;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class DiseaseServiceImpl implements DiseaseService  {
    @Autowired
    private DiseaseMapper diseaseDao;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        String queryString = queryPageBean.getQueryString();
        Integer pageSize = queryPageBean.getPageSize();
        Integer currentPage = queryPageBean.getCurrentPage();

         PageHelper.startPage(currentPage,pageSize);
         Page<Disease> page=diseaseDao.findPage(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void add(Disease disease) {
        diseaseDao.add(disease);
    }

    @Override
    public void delete(Integer diseaseId) {
        diseaseDao.deleteById(diseaseId);
    }

    @Override
    public Disease findById(Integer diseaseId) {
       Disease find=diseaseDao.findById(diseaseId);

        return find;
    }

    @Override
    public void update(Disease disease) {
        diseaseDao.update(disease);
    }
}
